<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>商城ETC卡现场领卡地址</title>
    <t:base type="jquery,easyui,tools,DatePicker"></t:base>
</head>
<body style="overflow-y: hidden" scroll="no">
<t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="table"
             action="mallEtcLivetakeAddressController.do?save">
    <input id="id" name="id" type="hidden" value="${mallEtcLivetakeAddressPage.id }">
    <input id="address_code_str" value="${addressCodeStr}" type="hidden">
    <table style="width: 600px;" cellpadding="0" cellspacing="1" class="formtable">
        <tr>
            <td align="right">
                <label class="Validform_label">
                    名字:
                </label>
            </td>
            <td class="value">
                <input class="inputxt" id="name" name="name"
                       value="${mallEtcLivetakeAddressPage.name}" datatype="*">
                <span class="Validform_checktip"></span>
            </td>
        </tr>
        <tr>
            <td align="right">
                <label class="Validform_label">
                    联系人:
                </label>
            </td>
            <td class="value">
                <input class="inputxt" id="contactname" name="contactname"
                       value="${mallEtcLivetakeAddressPage.contactname}" datatype="*">
                <span class="Validform_checktip"></span>
            </td>
        </tr>
        <tr>
            <td align="right">
                <label class="Validform_label">
                    联系电话:
                </label>
            </td>
            <td class="value">
                <input class="inputxt" id="mobilephone" name="mobilephone"
                       value="${mallEtcLivetakeAddressPage.mobilephone}" datatype="*">
                <span class="Validform_checktip"></span>
            </td>
        </tr>
        <tr>
            <td align="right">
                <label class="Validform_label">
                    所在区域:
                </label>
            </td>
            <td class="value">
                <select id="address_province" onchange="mallEtcLiveTakeAddressModule.addressChange(1,this)">
                    <c:forEach items="${regions}" var="region">
                        <option value="${region.id}">${region.regionName}</option>
                    </c:forEach>
                </select>
                <select id="address_city" onchange="mallEtcLiveTakeAddressModule.addressChange(2,this)">
                </select>
                <select id="address_county" name="areacode">
                </select>
            </td>
        </tr>
        <tr>
            <td align="right">
                <label class="Validform_label">
                    地址:
                </label>
            </td>
            <td class="value">
                <input class="inputxt" id="address" name="address"
                       value="${mallEtcLivetakeAddressPage.address}" datatype="*">
                <span class="Validform_checktip"></span>
            </td>
        </tr>
        <c:if test="${mallEtcLivetakeAddressPage.id != null}">
            <tr>
                <td align="right">
                    <label class="Validform_label">
                        创建时间:
                    </label>
                </td>
                <td class="value">
                    <input class="Wdate" onClick="WdatePicker()" style="width: 150px" id="createtime" name="createtime"
                           value="<fmt:formatDate value='${mallEtcLivetakeAddressPage.createtime}' type="date" pattern="yyyy-MM-dd"/>"
                           datatype="*">
                    <span class="Validform_checktip"></span>
                </td>
            </tr>
        </c:if>
    </table>
</t:formvalid>
</body>


<script type="text/javascript">
    $(function () {
        var id = $("#id").val();
        if(null == id || "" == id || typeof (id) == "undefined"){
            $("#address_province").change();
        }else{
            var addressCodeStr = $("#address_code_str").val();
            var addressCodeStrArrary = addressCodeStr.split(";");
            $("#address_province").val(addressCodeStrArrary[0].split("_")[1]);
            $("#address_province").change();
            $("#address_city").val(addressCodeStrArrary[1].split("_")[1]);
            $("#address_city").change();
            $("#address_county").val(addressCodeStrArrary[2].split("_")[1]);
        }
    });
    var mallEtcLiveTakeAddressModule = (function () {

        var module = {
            init: function () {

            },
            //地址改变事件
            addressChange: function (type, obj) {
                $.ajax({
                    url: 'mallEtcLivetakeAddressController.do?addressByCode',
                    type: 'post',
                    async: false,
                    data: {
                        code: $(obj).val()
                    },
                    cache: false,
                    success: function (data) {
                        var d = $.parseJSON(data);
                        if (d.success) {
                            var optionHtml = null;
                            $(d.obj).each(function (index) {
                                if(index == 0){
                                    optionHtml +=  "<option selected='selected' value='"+this.id+"'>"+this.regionName+"</option>"
                                }else{
                                    optionHtml += "<option value='" + this.id + "'>" + this.regionName + "</option>";
                                }
                            });
                            if (type == 1) {
                                $("#address_county").html("");
                                $("#address_city").html(optionHtml);
                                $("#address_city").change();
                            }else{
                                $("#address_county").html(optionHtml);
                            }
                        } else {
                            tip('系统异常');
                        }
                    }
                });
            },
        }
        return module;
    })();
</script>

